package koction.model.question;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import koction.model.consumer.ConsumerVO;
import koction.model.seller.SellerVO;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class QuestionBoardDaoImpl implements QuestionBoardDao {

	@Resource(name="sqlSessionTemplate")
	private SqlSessionTemplate sqlSessionTemplate;
	
	@Override
	public List<QuestionBoardVO> getQuestionBoardList(String pageNo) throws SQLException {
		return sqlSessionTemplate.selectList("question_board.getQuestionBoardList", pageNo);
	}

	@Override
	public int totalContent() throws SQLException {
		return sqlSessionTemplate.selectOne("question_board.totalContent");
	}

	@Override
	public int writeQuestion(QuestionBoardVO qvo) throws SQLException {
		return (Integer)sqlSessionTemplate.insert("question_board.writeQuestion",qvo);
	}

	@Override
	public QuestionBoardVO showContent(int no) throws SQLException {
		return sqlSessionTemplate.selectOne("question_board.showContentQuestionBoard", no);
	}

	@Override
	public void updateCount(HashMap<String, Integer> map) throws SQLException {
		sqlSessionTemplate.update("question_board.updateCount",map);
	}

	@Override
	public void deleteQuestionBoard(int no) throws SQLException {
		sqlSessionTemplate.delete("question_board.deleteQuestionBoard", no);	
	}
	
	@Override
	public void deleteSellerQuestionBoard(SellerVO svo) throws SQLException {
		sqlSessionTemplate.delete("question_board.deleteSellerQuestionBoard", svo);	
	}
	
	@Override
	public void updateQuestionBoard(QuestionBoardVO qvo) throws SQLException {
		sqlSessionTemplate.update("question_board.updateQuestionBoard", qvo);
	}

	@Override
	public void updateRestep(int ref, int restep) throws SQLException {
		HashMap<String, Integer> map = new HashMap<String, Integer>();
		map.put("ref", ref);
		map.put("restep", restep);
		sqlSessionTemplate.update("question_board.updateRestep", map);
	}

	@Override
	public int writeReplyQuestionBoard(QuestionBoardVO qvo) throws SQLException {
		return (Integer)sqlSessionTemplate.insert("question_board.writeReplyQuestionBoard",qvo);
	}

	@Override
	public String getReplyId(QuestionBoardVO qvo) throws SQLException {
		return sqlSessionTemplate.selectOne("question_board.getReplyId", qvo);
	}

	@Override
	public String replyCheck(String ref) throws SQLException {
		return sqlSessionTemplate.selectOne("question_board.replyCheck", ref);
	}

	@Override
	public void deleteReplyQuestion(ConsumerVO cvo) throws SQLException {
		sqlSessionTemplate.delete("question_board.deleteReplyQuestion", cvo);
		
	}

}
